/*The MIT License

Copyright (c) <2008> <Samir Menon>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#ifndef CSYNAPSE_H_
#define CSYNAPSE_H_

#include <iostream>
#include <cassert>
#include "CSystemClock.h"

namespace bis_neuron
{
using namespace std;

#define MAX_SYNAPSE_LEVEL 10
#define SYNAPSE_POTENTIATE_LEVEL 5
#define POTENTIATED_SYNAPSE_STRENGTH 1.0
#define NON_POTENTIATED_SYNAPSE_STRENGTH 0.7

enum enum_synapse_type {Excitatory=1, Inhibitory=-1};

class CSynapse
{
protected:
	bool syn_is_potentiated;
	unsigned int level;
	unsigned int from_neuron;
	enum_synapse_type synapse_type_modifier;
	NEURON_CLOCK pre_spk_time, post_spk_time;
	float pot_syn_strength, non_pot_syn_strength;//Synapse strength
	
	void potentiate(){	syn_is_potentiated = true;	}
	void depress(){	syn_is_potentiated = false;	}
	
public:
	CSynapse(int type = 1,
			 float arg_pot_syn_strength = POTENTIATED_SYNAPSE_STRENGTH, 
			 float arg_non_pot_syn_strength = NON_POTENTIATED_SYNAPSE_STRENGTH);
	~CSynapse();
	bool is_potentiated(){	return syn_is_potentiated;	}
	void reset(){	level=0;	syn_is_potentiated = false;	}
	
	float syn_vm_jump();//Returns the membrane-voltage jump @ a spike
		
	//Wrappers:
	void set_from_neuron(const unsigned int & arg_from_neuron);
	unsigned int get_from_neuron(){	return from_neuron;	}
	
	void get_pot_syn_strength(float & arg_pot_syn_strength)
	{	arg_pot_syn_strength = non_pot_syn_strength;	}	
	void get_non_pot_syn_strength(float & arg_non_pot_syn_strength)
	{	arg_non_pot_syn_strength = pot_syn_strength;	}
	void set_syn_strength(const float & arg_non_pot_syn_strength, 
												const float & arg_pot_syn_strength)	{
		non_pot_syn_strength = arg_non_pot_syn_strength;
		pot_syn_strength = arg_pot_syn_strength;		
	}
	

	void pre_event(NEURON_CLOCK &arg_time);
	void post_event(NEURON_CLOCK &arg_time);		
};

}

#endif /*CSYNAPSE_H_*/
